//
//  HomePageModel.m
//  Mtime2.0
//
//  Created by 凉气的Mac on 16/9/5.
//  Copyright © 2016年 凉气的Mac. All rights reserved.
//

#import "HomePageModel.h"

#import "MtimeNetWorkTools.h"

@implementation HomePageModel


+(instancetype)homePageModelWithDict:(NSDictionary *)dict{

    HomePageModel *model = [[HomePageModel alloc]init];
    
    [model setValuesForKeysWithDictionary:dict];
    
    return model;

}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
}

+(void)homePageModelWithURL:(NSString *)urlString Success:(void(^)(NSArray *modelArray))successBlock error:(void(^)())errorBlock{
    
    MtimeNetWorkTools *manager = [MtimeNetWorkTools sharedManager];
    


    
    [manager GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary * _Nullable responseObject) {
        
        
        NSArray *array = responseObject[@"data"];
        
        NSMutableArray *muArray = [NSMutableArray array];
        
        [array enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            HomePageModel *model = [HomePageModel homePageModelWithDict:obj];
            
            [muArray addObject:model];
            
        }];
        
        if (successBlock) {
            successBlock(muArray.copy);
        }

        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        if (errorBlock) {
            errorBlock();
        }
        
        
    }];
    
    


}

@end





































